﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace GJB.MVVMLesson.Bae
{
    public class CommandBase : ICommand
    {
        //通知 ：当前按钮检查可用条件  触发一次CanExecute
        public event EventHandler? CanExecuteChanged;
        public void DoExecuteChanged()
        {
            CanExecuteChanged?.Invoke(this, EventArgs.Empty);
        }
        public bool CanExecute(object? parameter)
        {
            return DoCanExecute?.Invoke(parameter) == true; //做绑定的对象  可用
        }

        /// <summary>
        /// 执行过程        相当于ButtonClick 
        /// </summary>
        /// <param name="parameter"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void Execute(object? parameter)
        {
            DoExecute?.Invoke(parameter);
        }

        public Action<object> DoExecute { get; set; }
        public Func<object, bool> DoCanExecute { get; set; }
    }
}
